<?php 
  /**
    *
    * FILE:    cieListAll.php
    * LOCATION:      /root
    * REFERENCES:    admin.php
    *                				cieSearch.php
    *                				cieEdit.php
    * FUNCTION:      displays a table of consumers that are
    *                				returned from the database as a resultset
    *                				based on search parameters from cieSearch.php
    * DEPENDENCIES:  db_connect.php 
    * 
    * ==============================================================================
    * 
    * @version $Id: admin.php,v 0.1 2008/08/08
    * @copyright Copyright (c) none
    * @author chrisv
    * @license http://opensource.org/licenses/gpl-license.php GNU General 
    * Public License Version 2 (GPL v2)
    * 
    * ==============================================================================
    */
  //connect to database
	include('includes/db_connect.php');
	require_once('./classes/pagination.class.php');
 //main pagination settings
	$items = 10;
	$page = 1;
	$get_page = 0;
	if(isset($_GET['page'])){$get_page = sanitize($_GET['page']);}else{$get_page = NULL;} 
	//BEGIN PAGINATION CODE
 //THIS BLOCK HANDLES EMPTY SEARCH STRING
/* 
 if(isset($_GET['page']) and is_numeric($_GET['page']) and $page = $_GET['page']){
			$limit = " LIMIT ".(($page-1)*$items).",$items";
 }else{
			$limit = " LIMIT $items";
 }
 */
  if(isset($get_page) and is_numeric($get_page) and $page = $get_page){
			$limit = " LIMIT ".(($page-1)*$items).",$items";
 }else{
			$limit = " LIMIT $items";
 }
 
	//$sqlStr = "SELECT * FROM consumer";
 $sqlStr = "SELECT c.id, 
														c.last_name, 
                    c.first_name, 
                    c.city, 
                    c.phone, 
                    c.address, 
                    c.zip, 
                    c.phone, 
                    ls.name as state
             FROM   consumer c, 
                    lst_state ls 
             WHERE  c.state_id = ls.id 
             ORDER BY c.last_name asc";
	$sqlStrAux = "SELECT count(*) as total FROM consumer";
	$aux = mysql_fetch_assoc(mysql_query($sqlStrAux));
	$query = mysql_query($sqlStr.$limit);
  echo "<h1 class=\"gt-notice-box\">
						<span style=\"font-size:2.5em; font-weight:bold; color:#00FF00;\">"
							.$aux['total'].
						"</span> Consumer case files were found in the database.</h1>";
	if($aux['total']>0){
				$p = new pagination;
				$p->Items($aux['total']);
				$p->limit($items);
				$p->target("admin.php?action=cielistall");
				$p->currentPage($page);
				$p->calculate();
				$p->changeClass("pagination");
?>
             <!-- SET UP TABLE  FOR FULL RESULTSET-->
             <table class="gt-list-table" border="0">
                   <thead> 
                      <tr>
                         <th>Full Name</th>
                         <th>Address</th>
                         <th>City</th>
                         <th>State</th>
                         <th>Zip</th>
                         <th>Phone</th>
                     </tr>
                  </thead>
                  <tbody>
<?php
      while($row = mysql_fetch_assoc($query)){
					if($i%2==0) {
						echo "<tr class='even'>";
       }else {
         echo "<tr class='odd'>";
       }
?>
                        <td>
                            <a href="admin.php?action=cieedit&id=<?php echo $row["id"]; ?>">
                                 <?php echo $row["last_name"].", ".$row["first_name"]; ?>
                            </a>
                        </td>
                        <td><?php echo $row["address"]; ?></td>
                        <td><?php echo $row["city"]; ?></td>
                        <td><?php echo $row["state"]; ?></td>
                        <td><?php echo $row["zip"]; ?></td>
                        <td><?php echo $row["phone"]; ?></td>
                   </tr>
<?php
        $i++;     
      }  //END WHILE recordset fetch
?>
				</tbody>
              </table>
              <!-- END RESULTSET TABLE -->
<?php
			echo"<p style=\"margin-top: 15px; font-size:1.2em; font-weight:bold;\"> Navigate Your Search Results: ";
	      $p->show();
			echo"</p>";
         }else{
		echo "<h2><div class=\"gt-error\">There no are records to show.</div></h2>.";
         } //ENDS routine for EMPTY SEARCH STRING
?>
   <br/>
<!-- USER HAS OPTION TO CREATE NEW CONSUMER CASE FILE -->
<p style="text-align:right;">
				<a style="background-image:url('./images/gt/btn-blank-long.jpg');
											background-repeat:no-repeat;
											border:none;
											line-height:3em;
											padding:7px 25px 7px 15px;
											width:160px;
											height: 30px;
											color: #fff;
											font-weight:bold;
											text-decoration:none;" 
							class="btn" href="admin.php?action=cieedit&id=0">
				<strong>Create New Case File</strong>
		</a>
</p>